/*
 * 立创开发板软硬件资料与相关扩展板软硬件资料官网全部开源
 * 开发板官网：www.lckfb.com
 * 技术支持常驻论坛，任何技术问题欢迎随时交流学习
 * 立创论坛：https://oshwhub.com/forum
 * 关注bilibili账号：【立创开发板】，掌握我们的最新动态！
 * 不靠卖板赚钱，以培养中国工程师为己任
 * Change Logs:
 * Date           Author       Notes
 * 2024-03-26     LCKFB-LP    first version
 */
 
#ifndef __BOARD_H__
#define __BOARD_H__

#include "stm32f10x.h"

#define BUTTONn 1
#define COMn 1

typedef enum
{
    COM1 = 0,
    COM2
} COM_TypeDef;

typedef enum
{
    LED1 = 0,
    LED2,
    LED3,
    LED4,
} LED_TypeDef;

typedef enum
{
    BUTTON_TAMPER = 0,
    BUTTON_KEY = 1,
    BUTTON_RIGHT,
    BUTTON_LEFT,
    BUTTON_UP,
    BUTTON_DOWN,
    BUTTON_SEL
} Button_TypeDef;

typedef enum
{
    BUTTON_MODE_GPIO = 0,
    BUTTON_MODE_EXTI = 1
} ButtonMode_TypeDef;

/**
 * @brief Tamper Button
 */
#define TAMPER_BUTTON_PIN               GPIO_Pin_13
#define TAMPER_BUTTON_GPIO_PORT         GPIOC
#define TAMPER_BUTTON_GPIO_CLK          RCC_APB2Periph_GPIOC
#define TAMPER_BUTTON_EXTI_LINE         EXTI_Line13
// #define TAMPER_BUTTON_EXTI_PORT_SOURCE  EXTI_PortSourceGPIOC
// #define TAMPER_BUTTON_EXTI_PIN_SOURCE   EXTI_PinSource13
#define TAMPER_BUTTON_EXTI_IRQn         EXTI15_10_IRQn


/**
 * * @brief 定义 COM1, 连接到 USART1
 */
#define EVAL_COM1                      USART1
#define EVAL_COM1_CLK                RCC_APB2Periph_USART1

#define EVAL_COM1_TX_PIN             GPIO_Pin_9
#define EVAL_COM1_TX_GPIO_PORT       GPIOA
#define EVAL_COM1_TX_GPIO_CLK        RCC_APB2Periph_GPIOA

#define EVAL_COM1_RX_PIN             GPIO_Pin_10
#define EVAL_COM1_RX_GPIO_PORT       GPIOA
#define EVAL_COM1_RX_GPIO_CLK        RCC_APB2Periph_GPIOA

void board_init(void);

void delay_us(uint32_t us);
void delay_ms(uint32_t ms);

void delay_1us(uint32_t us);
void delay_1ms(uint32_t ms);

void stm32_PBInit(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode);
uint32_t stm32_PBGetState(Button_TypeDef Button);
void stm32_COMInit(COM_TypeDef COM, USART_InitTypeDef* USART_InitStruct);

#endif
